package com.tanhua.server.service;

import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.autoconfig.template.HuanXinTemplate;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.HuanXinUserVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ck
 * @date 2021/11/16 15:30
 */
@Service
public class HuanXinService {

    @Autowired
    private HuanXinTemplate huanXinTemplate;

    @DubboReference
    private UserApi userApi;
    /**
     * 查询当前环信账号
     * 1、获取当前id，根据规则进行拼接
     * 2、获取当前用户id，查询用户
     * @return
     */
    public HuanXinUserVo findHuanXinUser() {
        HuanXinUserVo vo = new HuanXinUserVo();
        //1、获取当前用户id
        Long userId = UserHolder.getUserId();
        //2、查询用户
        User user = userApi.getUser(userId);

        if (user == null){
            return null;
        }
        vo.setUsername(user.getHxUser());
        vo.setPassword(user.getHxPassword());
        return vo;
    }
}
